package org.grottarossa.business;

import java.io.IOException;

import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
import org.grottarossa.domain.CaseFolder;
import org.grottarossa.domain.Record;
import org.grottarossa.query.SolrServerCreator;
import org.grottarossa.test.DataGenerator;

public class IndexService {
	
	private SolrServerCreator solr;

	public SolrServerCreator getSolr() {
		return solr;
	}

	public void setSolr(SolrServerCreator solr) {
		this.solr = solr;
	}
	
	public synchronized void indexCaseFolder(CaseFolder caseFolder){}
	
	public synchronized void indexRecord(Record record)
	{
		
		
	}
	public synchronized void updateIndexCasefolder(CaseFolder caseFolder){}
	public synchronized void updateIndexRecord(Record record){}
	public synchronized void removeIndexCasefolder(CaseFolder caseFolder){}
	public synchronized void removeIndexRecord(Record record){}	

	public void indexDoc() throws IOException, SolrServerException
	{
	 	SolrServer server = solr.getServer();
	 	
	 	CommonsHttpSolrServer srv = null;
	 	if(server instanceof CommonsHttpSolrServer)
	 	{
	 		srv =(CommonsHttpSolrServer) server;
	 	}
	 	
	 	DataGenerator gen = new DataGenerator();
	 	
	 	srv.ping();
	 	srv.add(gen.caseGenerator().getRecord());
	 	srv.commit();
	 	System.out.println("Server: is up: "+server);
	}
}
